package com.kjc.demo.coapserver;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import org.eclipse.californium.core.CoapClient;
import org.eclipse.californium.core.CoapResponse;
import org.eclipse.californium.core.Utils;
import org.eclipse.californium.elements.exception.ConnectorException;

public class GETClientTest {
    public static void main(String[] args) throws URISyntaxException, ConnectorException, IOException {
        URI uri = null;
        // 创建一个资源请求hello资源，注意默认端口为5683
        uri = new URI("localhost:5683/hello?name=kangjichang");
        CoapClient client = new CoapClient(uri);
        CoapResponse response = client.get();
        if(response !=null){
            // 打印请求状态码
            System.out.println(response.getCode());
            // 选项参数
            System.out.println(response.getOptions());
            // 获取内容文本信息
            System.out.println(response.getResponseText());
            System.out.println("\nAdvanced\n");
            // 打印格式良好的输出
            System.out.println(Utils.prettyPrint(response));
        }
    }
}

